﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AccuntBindUser.aspx.cs" Inherits="IsPay.View.AccuntBindUser" %>

<%@ Import Namespace="DataServer.Entities" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>账户绑定商户</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- Bootstrap 使用了2的,IE兼容性更好-->
    <link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
    <script src="../Scripts/jquery-1.10.2.min.js"></script>
    <script src="../bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript">
        function AccuntSelect() {
            var selectuser = document.getElementById("seluserid");
            var usertb = document.getElementById("usermodifytable");
            var selaccunt = document.getElementById("selaccunt");
            var txtactid = document.getElementById("accuntid");
            var selindx = selaccunt.selectedIndex;
            txtactid.value = "";
            selectuser.innerHTML = "";
            if (usertb.rows.length > 1) {
                for (var i = usertb.rows.length-1; i >0; i--) {
                    usertb.deleteRow(i);
                }
            }
            if (selindx >= 0) {
                var stracid = selaccunt.options[selindx].value;
                if (stracid.length <= 0) {
                    
                } else {
                    
                    txtactid.value = stracid;
                    $.post("AccuntBindUser.aspx", { ASKTYPE: "AJAX", SELACCUNTID: stracid }, function (result) {
                        //alert(result);
                        var jsonObj = eval('(' + result + ')');
                        var jsonsignuser = eval('(' + jsonObj.SINGNUSER + ')');
                        var jsonunsignuser = eval('(' + jsonObj.UNSINGNUSER + ')');                        
                       
                        if (jsonsignuser.length > 0) {
                            for (var i = 0; i < jsonsignuser.length; i++) {
                                usertb.insertRow(1);
                                usertb.rows[1].insertCell().innerHTML = "<input type=\"checkbox\" style=\"width: 20px\" />";
                                usertb.rows[1].insertCell().innerHTML = "<input type=\"checkbox\" style=\"width: 20px\" />";
                                usertb.rows[1].insertCell().innerHTML =  jsonsignuser[i].UserId ;
                                usertb.rows[1].insertCell().innerHTML =  jsonsignuser[i].UserName;
                                usertb.rows[1].insertCell().innerHTML =  jsonsignuser[i].Email;
                                usertb.rows[1].insertCell().innerHTML =  jsonsignuser[i].Telephone ;
                            }
                        }
                        if (jsonunsignuser.length > 0) {
                            for (var i = 0; i < jsonunsignuser.length; i++) {
                                selectuser.innerHTML = selectuser.innerHTML + "<option value=\"" + jsonunsignuser[i].UserId + "\">" + jsonunsignuser[i].UserName + "</option>";
                            }
                        }

                    });
                }

            } else {
               
            }
        }

        function OnAddUser() {
            var selectuser = document.getElementById("seluserid");
            if (selectuser.selectedIndex >= 0) {
                var usertb = document.getElementById("usermodifytable");
                var sindx = selectuser.selectedIndex;
                var susrid = selectuser.options[sindx].value;
                var susrname = selectuser.options[sindx].text;
                if (susrid.length > 0) {
                    if (usertb.rows.length > 0) {
                        for (var i = 0; i < usertb.rows.length; i++) {
                            var cnode = usertb.rows[i].cells[2].getElementsByTagName("input");
                            var cellv = "";
                            if (cnode.length > 0) {
                                if (cnode[0].type == "checkbox") {
                                    cellv = cnode[0].checked;
                                } else {
                                    cellv = cnode[0].value;
                                }

                            } else {
                                cellv = usertb.rows[i].cells[2].innerText;
                            }
                            if (cellv == susrid) {
                                alert("用户已经添加请勿重复添加");
                                return;
                            }
                        }
                    }
                }
                usertb.insertRow(1);
                usertb.rows[1].insertCell().innerHTML = "<input type=\"checkbox\" style=\"width: 20px\" checked=\"checked\"/>";
                usertb.rows[1].insertCell().innerHTML = "<input type=\"checkbox\" style=\"width: 20px\" />";
                usertb.rows[1].insertCell().innerHTML = susrid ;
                usertb.rows[1].insertCell().innerHTML =  susrname ;
                usertb.rows[1].insertCell().innerHTML = "";
                usertb.rows[1].insertCell().innerHTML = "";
            }
        }
        function OnModifyMenu() {
            var jasonstr = "";
            var tableObj = document.getElementById("usermodifytable");
            var ch = new Array();
            var edittable = [];
            for (var i = 0; i < tableObj.rows.length; i++) {    //遍历Table的所有Row
                var dataRow = {};
                for (var j = 0; j < tableObj.rows[i].cells.length; j++) {   //遍历Row中的每一列

                    var cellv = "";
                    var cnode = tableObj.rows[i].cells[j].getElementsByTagName("input");
                    if (cnode.length > 0) {
                        if (cnode[0].type == "checkbox") {
                            cellv = cnode[0].checked;
                        } else {
                            cellv = cnode[0].value;
                        }

                    } else {
                        cellv = tableObj.rows[i].cells[j].innerText.trim();
                    }
                    if (i == 0) {
                        ch[j] = cellv;
                    } else {
                        dataRow[ch[j]] = cellv;
                    }
                }
                if (i > 0) {
                    if (dataRow.addflag || dataRow.deleteflag)
                        edittable.push(dataRow);
                }

            }
            jasonstr = JSON.stringify(edittable);
            document.getElementById("updatejason").value = jasonstr;
            document.getElementById("UserAccuntModify").submit();
        }
    </script>

</head>
<body>
    <div class="container-fluid">
        <form  id="UserAccuntModify" method="post" action="AccuntBindUser.aspx?ASKTYPE=EDIT">
            <div class="row-fluid">
                <div class="span12">
                    <table>
                        <tr>
                            <td>账号:</td>
                            <td>
                                <select id="selaccunt" name="selaccunt" onchange="AccuntSelect()"> <option value=""></option>
                                    <%if (lsAccunt != null && lsAccunt.Count() > 0)
                                        { %>
                                    <%foreach (Accunt act in lsAccunt)
                                        { %>
                                    <option value="<%=act.AccuntId %>"><%=act.AccuntName %></option>
                                    <%} %>
                                    <%} %>
                                </select></td>
                        </tr>
                    </table>
                </div>
            </div>
            <div class="row-fluid">
                <div class="span12">
                </div>
                <table>
                    <tr>
                        <td>商户ID<select id="seluserid" name="seluserid"> </select></td><td><button type="button" class="btn btn-primary" data-toggle="button" onclick="OnAddUser()">添加</button></td>
                    </tr>
                </table>
            </div>
            <div class="row-fluid">
                <div class="span12">
                     <input type="hidden" id="updatejason" name="updatejason" value="" />
                    <button type="button" class="btn btn-primary" data-toggle="button" style="float:left" onclick="OnModifyMenu()">保存</button>
                    <asp:Label ID="lblMsg" runat="server" Text="" BackColor="#CC3300" Font-Bold="True"></asp:Label>
                </div>
                <div class="span12">
                    <input type="hidden" id="accuntid" name="accuntid" value="" />
                    <table class="table table-striped" id="usermodifytable">
                        <tr>
                            <th>
                                <input type="hidden" name="headcell6" id="headcell6" value="addflag" />添加</th>
                            <th>
                                <input type="hidden" name="headcell7" id="headcell7" value="deleteflag" />失效</th>
                            <th>
                                <input type="hidden" name="headcell1" id="headcell1" value="userid" />商户ID</th>
                            <th>
                                <input type="hidden" name="headcell2" id="headcell2" value="username" />商户名</th>
                            <th>
                                <input type="hidden" name="headcell3" id="headcell3" value="email" />邮箱</th>
                            <th>
                                <input type="hidden" name="headcell4" id="headcell4" value="telephone" />电话</th>
                        </tr>
                    </table>
                </div>
            </div>
        </form>
    </div>

</body>
</html>
